/**
 * Created by mantoo on 2018/4/10.
 */


// var newwindow=window.open("about:blank");
// window.focus();
// $.ajax({
//     url:form.attr('action'),
//     data:form.serialize(),
//     dataType: 'json',
//     async:false
// }).done(function(o){
//     if(o.success){
//         if(o.data){
//             newwindow.location.href="http://www.XXX.com";
//                         newwindow.focus();
//         }else{
//             newwindow.close();
//         }
//     }else{
//         newwindow.close();
//     }
// }).fail(function(){newwindow.close();});



    allpick = {

    };

// 将所有.ui-choose实例化
	$('.ui-choose').ui_choose();

    // uc_04 select 多选
	var education = $('#education').ui_choose();
	education.click = function(value, item) {
	    console.log('click', value);
	    intoData('education',value);
	};
	// education.change = function(value, item) {
	//     console.log('change', value);
	//     intoData('education',value);
    //
	// };
	var experience = $('#experience').ui_choose();
	experience.click = function(value, item){
	    console.log('click', value);
	    intoData('experience',value);
	};
	// experience.change = function(value, item) {
	//     console.log('change', value);
	//     intoData('experience',value);
    //
	// };

// {#	// uc_04 select 多选#}
// {#	var uc_04 = $('#uc_04').ui_choose();#}
// {#	uc_04.click = function(value, item) {#}
// {#	    console.log('click', value);#}
// {#	    intoData(value);#}
// {#	};#}
// {#	uc_04.change = function(value, item) {#}
// {#	    console.log('change', value);#}
// {#	    intoData();#}
// {##}
// {#	};#}

	function intoData(key,value) {

        console.log(key);
        oURL = "/hide/ReckonJob/ReturnPick/?key=" + key +"&value=";
	    if (key == "paging" ){
            oURL += value;

        }
        else if (key == "directSearch" ){
            oURL += value;
        }
        else{
            oURL = "/hide/ReckonJob/ReturnPick/?key=" + key +"&value=";
            for(i in value){
                oURL += value[i] + "-";

            }
        }
        console.log('item:', oURL);
	    $.get(oURL,function (self_data) {
	        $('.delId').remove(); // 清掉所有class中是delId的元素，包括页码和内容
	        data = JSON.parse(self_data);
            console.log('change', data);
// {#            console.log(data.Analysis);#}
	    for (count in data.Analysis){
            console.log(data.Analysis[count]);
            x = data.Analysis[count];
            str = '<tbody class=\"delId\">' +
                '<tr class="over_th">'
                + '<td >' + x[0] + '</td>'
                + '<td ><a href="javascript: detail(' + x[0] + ');">' + x[1] + '</a></td>'
                +'<td >' + x[9] + '</td>'
                + '<td >' + x[8] + '</td>'
                + '<td >' + x[11] + '</td>'
                + '<td >' + x[10] + '</td>'
                + '<td >' + x[3] + '</td>'
                + '<td >' + x[4] + '</td>'
                +' </tr>' +
                '</tbody>' ;
            //之前跳转详情页为调用js进行submit，现改成利用get直接请求链接，可以实现新窗口打开，，应该
            //<div class=\"post clearfix delId\" style=\"border: 3px;border-collapse: inherit;\"><div class=\"content\" style=\"width:auto;\"><h4><b><a target=\"view_window\" href=\"javascript: detail( "+
             //   x[0] + ");\" title=\"View permalink Baltic Park Molo\" style=\"font-family: '微软雅黑'\">" +
            str1 = "<div id='tableStyle' class=\"delId\" style=\"color: #555;border: 1px solid #ededed;margin-top: 18px;padding: 14px 15px 0;\"><div class=\"post clearfix delId\" style=\"border: 3px;border-collapse: inherit;\"><div class=\"content\" style=\"width:auto;\"><h4><b><a target=\"view_window\" href=\"/hide/ReckonJob/Details?hidDetail= "+
                x[0] + "\" title=\"点击浏览详情\" style=\"font-family: '微软雅黑';font-size: 16px;color: #00b38a;\">" +
                x[1] + "</a></b><span>&nbsp&nbsp[" +
                x[3] + "]</span></h4><p style=\"font-family:'微软雅黑 Light'\">\&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp\" "+
                x[6] + "</p></div><div class=\"meta\" style='width: 100%;height: 40px;padding: 0 15px;background-color: #fafafa;'><span class=\"pull-left\"><span style=\"color:rgb(241,86,32)\">"+
                x[15] + "</span> <a href=\"/index/policy/detail\">"  +
                x[5] + "</a> - " +
                x[4] + "</span><span class=\"pull-right\" style=\"font-family: '微软雅黑';\"><b><a href=\"javascript: detail("+
                x[0] + ");\">查看详情</a></b></span></div></div></div>";
// {#             $('#intoData').after();#}
// {#             $('#intoData').after();#}
// {#            $('#intoData').after();#}
// {#            $('#intoData').after();#}
// {#            $('#intoData').after();#}
// {#            $('#intoData').after();#}

            $('#intoData').before(str1);
        }
        uploadPaging(data);


	    });
    }

    function uploadPaging(data) {
	    console.log(uploadData.page_meg);
// {#         data = JSON.parse(uploadData);#}
         $('#hidPageIndex').val(data.page_meg.now_page);
        strPading = "<ul class=\"delId\" id=\"input_area\"\>";
        for (foo in data.page_meg.page_count_list){
                //console.log(data.page_meg.page_count_list[foo]);
                if (data.page_meg.page_count_list[foo] < 11 ) {
                    if (data.page_meg.page_count_list[foo] == data.page_meg.now_page) {
                        strPading += "<li class=\"active\"><a href=\"javascript: paging(" + data.page_meg.page_count_list[foo] + ");\">" + data.page_meg.page_count_list[foo] + "</a></li>"
                    }
                    else {
                        strPading += "<li><a href=\"javascript: paging(" + data.page_meg.page_count_list[foo] + ");\"> " + data.page_meg.page_count_list[foo] + "</a></li>"
                    }
                }
                if(data.page_meg.page_count_list[foo] == data.page_meg.page_count ) {
                    strPading += " <li class=\"empty-space\">....</li>";
                    if (data.page_meg.page_count_list[foo] == data.page_meg.now_page) {
                        strPading += "<li class=\"active\"><a href=\"javascript: paging(" + data.page_meg.page_count_list[foo] + ");\">" + data.page_meg.page_count_list[foo] + "</a></li>"
                    }
                    else {
                        strPading += "<li><a href=\"javascript: paging(" + data.page_meg.page_count_list[foo] + ");\"> " + data.page_meg.page_count_list[foo] + "</a></li>"
                    }
                }
        }
            strPading += "</ul><p class=\"delId\">第 <i style=\"color:rgb(241, 86, 32);\">" + data.page_meg.now_page + "</i> 页 | 共 <i style=\"color:rgb(241, 86, 32);\">" +
            data.page_meg.page_count+ "</i> 页</p>";
            console.log(strPading);
            $('#uploadData').append(strPading);
            $('#uploadDataside').append(strPading);
        }

// {#    var pTime = $('#pTime').data('ui-choose'); // 取回已实例化的对象#}
// {#	pTime.click = function(index, item) {#}
// {#	    console.log('click', index, item.text())#}
// {#	};#}
// {#	pTime.change = function(index, item) {#}
// {#	    console.log('change', index, item.text())#}
// {#	};#}
// {#	// uc_01 ul 单选#}
// {#	var uc_01 = $('#uc_01').data('ui-choose'); // 取回已实例化的对象#}
// {#	uc_01.click = function(index, item) {#}
// {#	    console.log('click', index, item.text())#}
// {#	};#}
// {#	uc_01.change = function(index, item) {#}
// {#	    console.log('change', index, item.text())#}
// {#	};#}
// {##}
// {#	// uc_02 select 单选#}
// {#	var uc_02 = $('#uc_02').data('ui-choose');#}
// {#	uc_02.click = function(value, item) {#}
// {#	    console.log('click', value);#}
// {#	    intoData();#}
// {#	};#}
// {#	uc_02.change = function(value, item) {#}
// {#	    console.log('change', value);#}
// {#	    intoData();#}
// {#	};#}
// {##}
// {#	// uc_03 ul 多选#}
// {#	var uc_03 = $('#uc_03').data('ui-choose');#}
// {#	uc_03.click = function(index, item) {#}
// {#	    console.log('click', index);#}
// {#	    intoData();#}
// {#	};#}
// {#	uc_03.change = function(index, item) {#}
// {#	    console.log('change', index);#}
// {#	    intoData();#}
// {#	};#}